home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Mac Power 1997 December
/
MACPOWER-1997-12.ISO.7z
/
MACPOWER-1997-12.ISO
/
AMUG
/
PROGRAMMING
/
Raven 1.2.sit
/
Raven 1.2
/
Source
/
Foundation
/
Common
/
ZExceptions.h
< prev
next >
Wrap
Text File
|
1997-08-16
|
6KB
|
201 lines
/*
* File: ZExceptions.h
* Summary: ANSI derived exception classes.
* Written by: Jesse Jones
*
* Copyright ゥ 1996-1997 Jesse Jones.
* For conditions of distribution and use, see copyright notice in ZTypes.h
*
* Classes: TBaseException - Base exception class
* TLogicException - Errors that could have been caught before running the program.
* TDomainException - A function's argument is outside the domain of the function.
* TInvalidArgumentException - An argument was completely bogus.
* TLengthException - An object was asked to grow past a hard-wired limit.
* TAssertException - Exception thrown by ASSERT and VERIFY (if ASSERTS_THROW is true).
* TRuntimeException - Errors that can only be caught at runtime.
* TRangeException - A function tried to produce a result that was outside its range.
* TOverflowException - An arithmatic overflow occured.
* TSystemException - A system error occured.
* TCancelException - The user has canceled an operation.
* TMemoryException - Not enough memory for operator new or other memory request.
* TSysMemoryException - Request for system memory failed (ie anything but operator new).
*
* Change History (most recent first):
*
* <2> 8/16/97 JDJ Uses OSStatus instead of OSErr. (OSStatus is a long).
* <1> 1/13/96 JDJ Created
*/
#pragma once
#include <String>
#include <ZTypes.h>
// ===================================================================================
// ANSI Exception Classes
// ===================================================================================
#if HAS_ANSI_EXCEPTIONS
typedef exception TBaseException;
typedef logic_error TLogicException;
typedef domain_error TDomainException;
typedef invalid_argument TInvalidArgumentException;
typedef length_error TLengthException;
typedef runtime_error TRuntimeException;
typedef range_error TRangeException;
typedef overflow_error TOverflowException;
// ・・ For some stupid reason bad_alloc doesn't descend from runtime_error.
// ・・ Hopefully this will be fixed so we can make TSysMemoryException
// ・・ハdescend from TRuntimeException.
typedef bad_alloc TMemoryException;
#else // HAS_ANSI_EXCEPTIONS
class TBaseException {
public:
virtual ~TBaseException();
TBaseException(const string& mesg);
virtual const char* what() const;
protected:
char mText[256];
};
class TLogicException : public TBaseException {
public:
TLogicException(const string& mesg) : TBaseException(mesg) {}
};
class TDomainException : public TLogicException {
public:
TDomainException(const string& mesg) : TLogicException(mesg) {}
};
class TInvalidArgumentException : public TLogicException {
public:
TInvalidArgumentException(const string& mesg) : TLogicException(mesg) {}
};
class TLengthException : public TLogicException {
public:
TLengthException(const string& mesg) : TLogicException(mesg) {}
};
class TRuntimeException : public TBaseException {
public:
TRuntimeException(const string& mesg) : TBaseException(mesg) {}
};
class TRangeException : public TRuntimeException {
public:
TRangeException(const string& mesg) : TRuntimeException(mesg) {}
};
class TOverflowException : public TRuntimeException {
public:
TOverflowException(const string& mesg) : TRuntimeException(mesg) {}
};
class TMemoryException : public TBaseException {
public:
TMemoryException() : TBaseException("Not enough memory (object heap)") {}
};
#endif // HAS_ANSI_EXCEPTIONS
// ===================================================================================
// PowerPlant Support
// ===================================================================================
#ifdef __PowerPlant__
class ExceptionCode {
public:
virtual ~ExceptionCode() {}
ExceptionCode(long errCode) {mErrorCode = errCode;}
ExceptionCode& operator=(long err) {mErrorCode = err; return *this;}
operator long() const {return mErrorCode;}
protected:
long mErrorCode;
};
class TSysMemoryException : public TMemoryException, public ExceptionCode {
public:
TSysMemoryException() : ExceptionCode(-108) {}
};
class TSystemException : public TRuntimeException, public ExceptionCode {
public:
TSystemException(OSStatus err, const string& mesg) : TRuntimeException(mesg), ExceptionCode(err) {mError = err;}
public:
OSStatus mError;
};
#endif
// ===================================================================================
// Raven Exception Classes
// ===================================================================================
#ifndef __PowerPlant__
class TSysMemoryException : public TMemoryException {
public:
TSysMemoryException() {}
};
class TSystemException : public TRuntimeException {
public:
TSystemException(OSStatus err, const string& mesg) : TRuntimeException(mesg) {mError = err;}
public:
OSStatus mError;
};
#endif
#if ASSERTS_THROW
class TAssertException : public TLogicException {
public:
TAssertException(const string& mesg) : TLogicException(mesg) {}
};
#endif
class TCancelException : public TRuntimeException {
public:
TCancelException(const string& mesg) : TRuntimeException(mesg) {}
};
// ===================================================================================
// Functions
// ===================================================================================
void ThrowIfNil(const void* ptr);
void ThrowOSErr(OSStatus err);
void ThrowIfOSErr(OSStatus err);
void ThrowIfResError();
void ThrowIfMemError();
void ThrowIfResFail(const void* ptr);
void ThrowIfMemFail(const void* ptr);
void ThrowIfQDError();